import type { MockMethod } from 'vite-plugin-mock'

export default [
  // 测试
  {
    url: '/api/test',
    method: 'get',
    // timeout: 5000,
    response: ({ body }: { body: { fileHash: string } }) => {
      debugger
      // return '成功'
      return {
        code: 200,
        data: {
          isComplete: false,
          existList: '成功',
        },
      }
    },
  },
  // 上传分片
  {
    url: '/api/upload_chunk1',
    method: 'post',

    response: async ({
      body,
    }: {
      body: { fileHash: string; chunkIndex: number; chunkData: string }
    }) => {
      debugger
      // 3%概率模拟上传失败
      if (Math.random() < 0.03) {
        return {
          code: 500,
          data: {
            message: '分片上传失败',
            error: '网络错误，分片上传失败',
          },
        }
      }

      // 模拟上传延迟（1-3秒）
      await new Promise((resolve) => setTimeout(resolve, 1000 + Math.random() * 2000))

      return {
        code: 200,
        data: {
          message: '分片上传成功',
          percent: 100,
        },
      }
    },
  },
  // 合并分片
  {
    url: '/api/merge_chunk',
    method: 'post',
    response: () => {
      return {
        code: 200,
        data: {
          message: '文件合并成功',
          fileUrl: 'https://example.com/files/mock-file.mp4',
        },
      }
    },
  },
] as MockMethod[]
